import { fileURLToPath, URL } from "node:url";
import { resolve } from "node:path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import unoCss from "unocss/vite";
import jsx from "@vitejs/plugin-vue-jsx";
import { viteInjectAppLoadingPlugin } from "./src/plugins/inject-app-loading/index";

// https://vitejs.dev/config/
export default defineConfig(async () => {
  const injectAppLoadingPlugin = await viteInjectAppLoadingPlugin();
  return {
    optimizeDeps: {
      include: [resolve(__dirname, "src/locales/langs/**")],
    },
    plugins: [vue(), unoCss(), jsx(), injectAppLoadingPlugin],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      host: "0.0.0.0",
      port: 5173,
      // cors: true,
      // proxy: {
      //   "/api": {
      //     target: "http://localhost:8085/api",
      //     changeOrigin: true,
      //     rewrite: (path) => path.replace("/api", ""),
      //   },
      // },
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            hack: `true; @import (reference) "${resolve("src/styles/global.less")}";`,
          },
          javascriptEnable: true,
        },
      },
    },
  };
});
